<template>
    <div>
        <h3>录入房价信息</h3>
       <table class="table">
              <thead>   
                <tr>
                    <th>标题</th>
                    <th><input type="text" v-model="obj.roomPriceTitle"></th>
                </tr>
                <tr>
                    <th>价格</th>
                    <th>
                        <input type="number" v-model="obj.roomPriceNum"> 
                    </th>
                </tr>
                <tr>
                    <th>房型</th>
                    <th>
                       <select v-model="obj.roomstypesId">
                        <option value="0">请选择房型</option>
                        <option v-for="a in typedata" :value="a.roomTypeId">{{ a.roomTypeName }}</option>
                       </select>
                    </th>
                </tr>
                <tr>
                    <th>描述</th>
                    <th><input type="text" v-model="obj.roomPriceInfo"></th>
                </tr>
                <tr>
                    <th colspan="2">
                        <input type="button" value="录入" class="btn btn-info" @click="AddPrice">
                    </th>
                </tr>
              </thead>
       </table>
       <a href="/showall">返回首页</a>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter()

onMounted(()=>{
   bindtype()
})
const obj=ref({
  "roomPriceTitle": "",
  "roomPriceNum": 0,
  "roomstypesId": 0,
  "roomPriceInfo": "",
  "solt": 0
})

const AddPrice=()=>{
    if(obj.value.roomPriceTitle=="")
{
     alert('标题不能为空!')
        return;
}
if(obj.value.roomPriceNum==0)
{
     alert('房价不能为空,必须大于0!')
        return;
}
if(obj.value.roomstypesId==0)
{
     alert('房型不能为空!')
        return;
}
if(obj.value.roomPriceInfo=="")
{
     alert('描述不能为空!')
        return;
}
    axios.post('/api/RoomPrice/AddPrice',obj.value).then(res=>{
    if(res.data>0)
     {
        alert('录入成功!!')
        router.push('/showprice')
     }
    else
    {
        alert('录入失败!!')
        return;
    }
    })
}
//绑定房型下拉框
const  typedata=ref([{
     "roomTypeId": 1,
    "roomTypeName": "单人房"
}])
const bindtype=()=>{
    axios.get('/api/RoomType/GetRoomType',{}).then(res=>{
        typedata.value=res.data
    })
}
</script>

<style scoped>

</style>